/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainJFrame.java
 *
 * Created on Nov 5, 2011, 11:35:06 AM
 * Do not change this file. 
 */
package isnmp.ui;

import isnmp.ui.ChildDevice.ChildActionEnum;
import isnmp.ui.dto.CPUInfo;
import isnmp.ui.dto.DeviceInfo;
import isnmp.ui.dto.MachineInfo;
import isnmp.ui.dto.StorageInfo;
import isnmp.ui.dto.ProgramInfo;
import isnmp.ui.dto.NetworkInfo;

import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.List;
import java.util.Vector;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;

import org.apache.log4j.Logger;

import sg.simple.snmp.provider.NetMapException;


public class MainJFrame extends javax.swing.JFrame {

	private DefaultMutableTreeNode root;
	//private ChildDevice childDevice;
	DefaultTreeModel defaultTreeModel;
	public static NetMapManager netMapManager;
	public static MainJFrame frameInstance;
	List<String> ips;
	Vector<String> urls;
	public static SNMPTableModel cpuInfoTableModel;
	public static SNMPTableModel diskInfoTableModel;
	public static SNMPTableModel processInfoTableModel;
	public static SNMPTableModel networkInfoTableModel;
        public static SNMPTableModel deviceInfoTableModel;
        public static MachineInfoTableModel machineInfoTableModel;

	private org.apache.log4j.Logger logger = Logger.getLogger(MainJFrame.class);

	/** Creates new form MainJFrame */
	public MainJFrame() {
		initComponents();
	}

	public void setUpUI() {
		this.netMapManager = NetMapManager.getInstance();
		initCustomCoponents();
		resetDataTabs();

		loadData();
		reloadUIComponents();
		setAlwaysOnTop(false);

		pack();

	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed"
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
	private void initComponents() {

		jFrame1 = new javax.swing.JFrame();
		jPanel1 = new javax.swing.JPanel();
		jLayeredPane1 = new javax.swing.JLayeredPane();
		jScrollPane1 = new javax.swing.JScrollPane();
		devices = new javax.swing.JTree();
		jTabbedPane1 = new javax.swing.JTabbedPane();
		jPanel2 = new javax.swing.JPanel();
        cpujPanel5 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
		jScrollPane5 = new javax.swing.JScrollPane();
        machineInfojTable = new javax.swing.JTable();
        ipjLabel = new javax.swing.JLabel();
        cpujPanel6 = new javax.swing.JPanel();
		jScrollPane4 = new javax.swing.JScrollPane();
		cpuInfoTable = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        deviceInfojPanel = new javax.swing.JPanel();
		jScrollPane2 = new javax.swing.JScrollPane();
        deviceInfoTable = new javax.swing.JTable();
        processesJPanel = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        processesjTable = new javax.swing.JTable();
        networkjPanel5 = new javax.swing.JPanel();
        jScrollPane8 = new javax.swing.JScrollPane();
        networkInfojTable = new javax.swing.JTable();
        storagejPanel = new javax.swing.JPanel();
        jScrollPane9 = new javax.swing.JScrollPane();
        storagejTable = new javax.swing.JTable();
		jPanel4 = new javax.swing.JPanel();
		jLabel2 = new javax.swing.JLabel();
		subNetmaskjTextField = new javax.swing.JTextField();
		jLabel3 = new javax.swing.JLabel();
		networkTimeoutjTextField1 = new javax.swing.JTextField();
		jLabel4 = new javax.swing.JLabel();
		snmpCommunityjTextField1 = new javax.swing.JTextField();
		jMenuBar1 = new javax.swing.JMenuBar();
		jMenu1 = new javax.swing.JMenu();
		jMenuItem1 = new javax.swing.JMenuItem();
		jMenu2 = new javax.swing.JMenu();
		jMenuItem2 = new javax.swing.JMenuItem();

        javax.swing.GroupLayout jFrame1Layout = new javax.swing.GroupLayout(jFrame1.getContentPane());
		jFrame1.getContentPane().setLayout(jFrame1Layout);
        jFrame1Layout.setHorizontalGroup(
            jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        jFrame1Layout.setVerticalGroup(
            jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
		setTitle("NetMap");
		setAlwaysOnTop(true);
		setResizable(false);

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));

        jLayeredPane1.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));

		devices.setModel((DefaultTreeModel) devices.getModel());
		devices.setName("devices"); // NOI18N
		jScrollPane1.setViewportView(devices);

		jScrollPane1.setBounds(0, 0, 170, 500);
		jLayeredPane1.add(jScrollPane1, javax.swing.JLayeredPane.DEFAULT_LAYER);

		jTabbedPane1.setName("Hardware"); // NOI18N

        cpujPanel5.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        cpujPanel5.setAutoscrolls(true);

        jLabel5.setText("Machine Info");

        machineInfojTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane5.setViewportView(machineInfojTable);

        javax.swing.GroupLayout cpujPanel5Layout = new javax.swing.GroupLayout(cpujPanel5);
        cpujPanel5.setLayout(cpujPanel5Layout);
        cpujPanel5Layout.setHorizontalGroup(
            cpujPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(cpujPanel5Layout.createSequentialGroup()
                .addGap(21, 21, 21)
										.addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(ipjLabel)
                .addContainerGap(412, Short.MAX_VALUE))
            .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 501, Short.MAX_VALUE)
        );
        cpujPanel5Layout.setVerticalGroup(
            cpujPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(cpujPanel5Layout.createSequentialGroup()
										.addContainerGap()
                .addGroup(cpujPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
										.addComponent(jLabel5)
                    .addComponent(ipjLabel))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 415, Short.MAX_VALUE))
        );

        cpujPanel6.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        cpujPanel6.setAutoscrolls(true);

        cpuInfoTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        cpuInfoTable.setName("cpuInfoTable"); // NOI18N
        jScrollPane4.setViewportView(cpuInfoTable);

        jLabel1.setText("CPU Info");

        javax.swing.GroupLayout cpujPanel6Layout = new javax.swing.GroupLayout(cpujPanel6);
        cpujPanel6.setLayout(cpujPanel6Layout);
        cpujPanel6Layout.setHorizontalGroup(
            cpujPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(cpujPanel6Layout.createSequentialGroup()
                .addGroup(cpujPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(cpujPanel6Layout.createSequentialGroup()
										.addContainerGap()
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 536, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        cpujPanel6Layout.setVerticalGroup(
            cpujPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(cpujPanel6Layout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 415, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addComponent(cpujPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(cpujPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, 516, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(cpujPanel6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(cpujPanel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Hardware", jPanel2);

        deviceInfoTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(deviceInfoTable);

        javax.swing.GroupLayout deviceInfojPanelLayout = new javax.swing.GroupLayout(deviceInfojPanel);
        deviceInfojPanel.setLayout(deviceInfojPanelLayout);
        deviceInfojPanelLayout.setHorizontalGroup(
            deviceInfojPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 1031, Short.MAX_VALUE)
        );
        deviceInfojPanelLayout.setVerticalGroup(
            deviceInfojPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 497, Short.MAX_VALUE)
        );

        jTabbedPane1.addTab("DeviceInfo", deviceInfojPanel);

        processesjTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane3.setViewportView(processesjTable);

        javax.swing.GroupLayout processesJPanelLayout = new javax.swing.GroupLayout(processesJPanel);
        processesJPanel.setLayout(processesJPanelLayout);
        processesJPanelLayout.setHorizontalGroup(
            processesJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 1031, Short.MAX_VALUE)
        );
        processesJPanelLayout.setVerticalGroup(
            processesJPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 497, Short.MAX_VALUE)
        );

        jTabbedPane1.addTab("Processes", processesJPanel);

        networkInfojTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane8.setViewportView(networkInfojTable);

        javax.swing.GroupLayout networkjPanel5Layout = new javax.swing.GroupLayout(networkjPanel5);
        networkjPanel5.setLayout(networkjPanel5Layout);
        networkjPanel5Layout.setHorizontalGroup(
            networkjPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(networkjPanel5Layout.createSequentialGroup()
                .addComponent(jScrollPane8, javax.swing.GroupLayout.PREFERRED_SIZE, 1271, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        networkjPanel5Layout.setVerticalGroup(
            networkjPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane8, javax.swing.GroupLayout.DEFAULT_SIZE, 497, Short.MAX_VALUE)
        );

        jTabbedPane1.addTab("Network", networkjPanel5);

        storagejTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane9.setViewportView(storagejTable);

        javax.swing.GroupLayout storagejPanelLayout = new javax.swing.GroupLayout(storagejPanel);
        storagejPanel.setLayout(storagejPanelLayout);
        storagejPanelLayout.setHorizontalGroup(
            storagejPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane9, javax.swing.GroupLayout.DEFAULT_SIZE, 1031, Short.MAX_VALUE)
        );
        storagejPanelLayout.setVerticalGroup(
            storagejPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane9, javax.swing.GroupLayout.DEFAULT_SIZE, 497, Short.MAX_VALUE)
        );

        jTabbedPane1.addTab("Storage", storagejPanel);

        jPanel4.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));

		jLabel2.setText("Subnet mask");

        subNetmaskjTextField.addMouseListener(new java.awt.event.MouseAdapter() {
					public void mouseExited(java.awt.event.MouseEvent evt) {
						subNetmaskjTextFieldMouseExited(evt);
					}
				});
        subNetmaskjTextField.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent evt) {
						subNetmaskjTextFieldActionPerformed(evt);
					}
				});
        subNetmaskjTextField.addFocusListener(new java.awt.event.FocusAdapter() {
					public void focusLost(java.awt.event.FocusEvent evt) {
						subNetmaskjTextFieldFocusLost(evt);
					}
				});

		jLabel3.setText("Network Time out");

        networkTimeoutjTextField1.addMouseListener(new java.awt.event.MouseAdapter() {
					public void mouseExited(java.awt.event.MouseEvent evt) {
						networkTimeoutjTextField1MouseExited(evt);
					}
				});
        networkTimeoutjTextField1.addFocusListener(new java.awt.event.FocusAdapter() {
					public void focusLost(java.awt.event.FocusEvent evt) {
						networkTimeoutjTextField1FocusLost(evt);
					}
				});

		jLabel4.setText("SNMP Community");

        snmpCommunityjTextField1.addMouseListener(new java.awt.event.MouseAdapter() {
					public void mouseExited(java.awt.event.MouseEvent evt) {
						snmpCommunityjTextField1MouseExited(evt);
					}
				});
        snmpCommunityjTextField1.addFocusListener(new java.awt.event.FocusAdapter() {
					public void focusLost(java.awt.event.FocusEvent evt) {
						snmpCommunityjTextField1FocusLost(evt);
					}
				});

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
		jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
										.addGap(33, 33, 33)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
														.addComponent(jLabel2)
														.addComponent(jLabel3)
														.addComponent(jLabel4))
										.addGap(152, 152, 152)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(snmpCommunityjTextField1)
                    .addComponent(networkTimeoutjTextField1)
                    .addComponent(subNetmaskjTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE))
                .addContainerGap(582, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
										.addGap(34, 34, 34)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(jLabel2)
                    .addComponent(subNetmaskjTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
										.addGap(33, 33, 33)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(jLabel3)
                    .addComponent(networkTimeoutjTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
										.addGap(29, 29, 29)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(jLabel4)
                    .addComponent(snmpCommunityjTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(337, Short.MAX_VALUE))
        );

		jTabbedPane1.addTab("Configurations", jPanel4);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
		jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLayeredPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 1036, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLayeredPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 525, Short.MAX_VALUE)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 525, Short.MAX_VALUE)
        );

		jTabbedPane1.getAccessibleContext().setAccessibleName("Hardware");

		jMenu1.setText("File");
        jMenu1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenu1ActionPerformed(evt);
            }
        });

		jMenuItem1.setText("Exit");
		jMenu1.add(jMenuItem1);

		jMenuBar1.add(jMenu1);

		jMenu2.setText("Help");

		jMenuItem2.setText("About Us");
		jMenu2.add(jMenuItem2);

		jMenuBar1.add(jMenu2);

		setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
		getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

		pack();
	}// </editor-fold>//GEN-END:initComponents

private void jMenu1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenu1ActionPerformed
    System.out.print("Exit......................");
}//GEN-LAST:event_jMenu1ActionPerformed

	private void subNetmaskjTextFieldActionPerformed(
			java.awt.event.ActionEvent evt) {// GEN-FIRST:event_subNetmaskjTextFieldActionPerformed
		String subnet = evt.getActionCommand();

	}// GEN-LAST:event_subNetmaskjTextFieldActionPerformed

	private void subNetmaskjTextFieldFocusLost(java.awt.event.FocusEvent evt) {// GEN-FIRST:event_subNetmaskjTextFieldFocusLost
		NetMapManager.setSubnetMask(((JTextField) evt.getSource()).getText());
	}// GEN-LAST:event_subNetmaskjTextFieldFocusLost

	private void subNetmaskjTextFieldMouseExited(java.awt.event.MouseEvent evt) {// GEN-FIRST:event_subNetmaskjTextFieldMouseExited
		NetMapManager.setSubnetMask(((JTextField) evt.getSource()).getText());
	}// GEN-LAST:event_subNetmaskjTextFieldMouseExited

	private void networkTimeoutjTextField1MouseExited(
			java.awt.event.MouseEvent evt) {// GEN-FIRST:event_networkTimeoutjTextField1MouseExited
		NetMapManager
				.setTimeout(Integer.parseInt(((JTextField) evt.getSource())
						.getText()));
	}// GEN-LAST:event_networkTimeoutjTextField1MouseExited

	private void networkTimeoutjTextField1FocusLost(
			java.awt.event.FocusEvent evt) {// GEN-FIRST:event_networkTimeoutjTextField1FocusLost
		NetMapManager
				.setTimeout(Integer.parseInt(((JTextField) evt.getSource())
						.getText()));
	}// GEN-LAST:event_networkTimeoutjTextField1FocusLost

	private void snmpCommunityjTextField1FocusLost(java.awt.event.FocusEvent evt) {// GEN-FIRST:event_snmpCommunityjTextField1FocusLost
		NetMapManager.setNetworkCommunity(((JTextField) evt.getSource())
				.getText());
	}// GEN-LAST:event_snmpCommunityjTextField1FocusLost

	private void snmpCommunityjTextField1MouseExited(
			java.awt.event.MouseEvent evt) {// GEN-FIRST:event_snmpCommunityjTextField1MouseExited
		NetMapManager.setNetworkCommunity(((JTextField) evt.getSource())
				.getText());
	}// GEN-LAST:event_snmpCommunityjTextField1MouseExited

	/**
	 * @param args
	 *            the command line arguments
	 */
	public static void main(String args[]) {

		/* Create and display the dialog */
		java.awt.EventQueue.invokeLater(new Runnable() {

			public void run() {
				NetMapConfigurationDialog dialog = new NetMapConfigurationDialog(
						frameInstance, true);
				dialog.addWindowListener(new java.awt.event.WindowAdapter() {

					@Override
					public void windowClosing(java.awt.event.WindowEvent e) {
						// System.exit(0);
					}
				});
				dialog.setVisible(true);

			}
		});

		/* Set the Nimbus look and feel */
		// <editor-fold defaultstate="collapsed"
		// desc=" Look and feel setting code (optional) ">
		/*
		 * If Nimbus (introduced in Java SE 6) is not available, stay with the
		 * default look and feel. For details see
		 * http://download.oracle.com/javase
		 * /tutorial/uiswing/lookandfeel/plaf.html
		 */
		try {
			for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager
					.getInstalledLookAndFeels()) {
				if ("Nimbus".equals(info.getName())) {
					javax.swing.UIManager.setLookAndFeel(info.getClassName());
					break;
				}
			}
		} catch (ClassNotFoundException ex) {
			java.util.logging.Logger.getLogger(MainJFrame.class.getName()).log(
					java.util.logging.Level.SEVERE, null, ex);
		} catch (InstantiationException ex) {
			java.util.logging.Logger.getLogger(MainJFrame.class.getName()).log(
					java.util.logging.Level.SEVERE, null, ex);
		} catch (IllegalAccessException ex) {
			java.util.logging.Logger.getLogger(MainJFrame.class.getName()).log(
					java.util.logging.Level.SEVERE, null, ex);
		} catch (javax.swing.UnsupportedLookAndFeelException ex) {
			java.util.logging.Logger.getLogger(MainJFrame.class.getName()).log(
					java.util.logging.Level.SEVERE, null, ex);
		}
		// </editor-fold>

		/* Create and display the form */
		java.awt.EventQueue.invokeLater(new Runnable() {

			public void run() {
				frameInstance = new MainJFrame();
				frameInstance.setResizable(false);

			}
		});
	}

	public void loadData() {
		loadConfiguration();
		loadDevices();
	}

	public void loadDevices() {
		ips = netMapManager.getIps();
	}

	// Variables declaration - do not modify//GEN-BEGIN:variables
	private javax.swing.JTable cpuInfoTable;
	private javax.swing.JPanel cpujPanel5;
    private javax.swing.JPanel cpujPanel6;
    private javax.swing.JTable deviceInfoTable;
    private javax.swing.JPanel deviceInfojPanel;
	private javax.swing.JTree devices;
    private javax.swing.JLabel ipjLabel;
	private javax.swing.JFrame jFrame1;
	private javax.swing.JLabel jLabel1;
	private javax.swing.JLabel jLabel2;
	private javax.swing.JLabel jLabel3;
	private javax.swing.JLabel jLabel4;
	private javax.swing.JLabel jLabel5;
	private javax.swing.JLayeredPane jLayeredPane1;
	private javax.swing.JMenu jMenu1;
	private javax.swing.JMenu jMenu2;
	private javax.swing.JMenuBar jMenuBar1;
	private javax.swing.JMenuItem jMenuItem1;
	private javax.swing.JMenuItem jMenuItem2;
	private javax.swing.JPanel jPanel1;
	private javax.swing.JPanel jPanel2;
	private javax.swing.JPanel jPanel4;
	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
	private javax.swing.JScrollPane jScrollPane4;
	private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane8;
    private javax.swing.JScrollPane jScrollPane9;
	private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable machineInfojTable;
    private javax.swing.JTable networkInfojTable;
	private javax.swing.JTextField networkTimeoutjTextField1;
    private javax.swing.JPanel networkjPanel5;
    private javax.swing.JPanel processesJPanel;
    private javax.swing.JTable processesjTable;
	private javax.swing.JTextField snmpCommunityjTextField1;
    private javax.swing.JPanel storagejPanel;
    private javax.swing.JTable storagejTable;
	private javax.swing.JTextField subNetmaskjTextField;
	// End of variables declaration//GEN-END:variables

	private void initCustomCoponents() {
		root = new DefaultMutableTreeNode("Devices");
		defaultTreeModel = new DefaultTreeModel(root);
		devices.setModel(defaultTreeModel);

				jMenuItem1.addActionListener(new AbstractAction("Exit") {

					public void actionPerformed(ActionEvent e) {
						try {
							// m_tree.repaint();
							System.exit(0);
						} catch (Exception ex) {
							logger.error(ex);
							JOptionPane.showMessageDialog(
									null,
									"Unable to exit due to - "
											+ ex.getMessage());
						}
		}
				});
		MouseAdapter ma = new MouseAdapter() {

			private ChildActionEnum menu;

			private void myPopupEvent(MouseEvent e) {
				int x = e.getX();
				int y = e.getY();
				Object obj = getClickedObject(e);
				JPopupMenu popup = new JPopupMenu();
				;
				Action a1, a2, a3, a4;
				if (obj instanceof ChildDevice) {
					final ChildDevice childDevice = (ChildDevice) obj;
					a1 = new AbstractAction("Restart") {

						public void actionPerformed(ActionEvent e) {
							try {
								// m_tree.repaint();
								childDevice.restart();
							} catch (NetMapException ex) {
								logger.error(ex);
								JOptionPane.showMessageDialog(
										null,
										"Unable to restart due to - "
												+ ex.getMessage());
							}
						}
					};

					a2 = new AbstractAction("Shutdown") {

						public void actionPerformed(ActionEvent e) {
							try {
								// m_tree.repaint();
								childDevice.shutdown();
							} catch (NetMapException ex) {
								logger.error(ex);
								JOptionPane.showMessageDialog(
										null,
										"Unable to shutdown due to - "
												+ ex.getMessage());
							}
						}
					};
					a3 = new AbstractAction("Block") {

						public void actionPerformed(ActionEvent e) {
							try {
								// m_tree.repaint();
								childDevice.block();
							} catch (NetMapException ex) {
								logger.error(ex);
								JOptionPane.showMessageDialog(
										null,
										"Unable to block due to - "
												+ ex.getMessage());
							}
						}
					};
					a4 = new AbstractAction("Remote Login") {

						public void actionPerformed(ActionEvent e) {
							try {
								// m_tree.repaint();
								
								new RemoteLogin().login(childDevice.getIp());
							} catch (Exception ex) {
								logger.error(ex);
								JOptionPane.showMessageDialog(null,
										"Unable to invoke remote login due to - "
												+ ex.getMessage());
							}
						}
					};

//					popup.add(a1);
//					popup.add(a2);
//					popup.add(a3);
					popup.add(a4);
				}

				popup.show((JTree) e.getSource(), x, y);


			}

			public void mousePressed(MouseEvent mouseEvent) {
				if (mouseEvent.isPopupTrigger()) {
					myPopupEvent(mouseEvent);
				}
				int modifiers = mouseEvent.getModifiers();
				if ((modifiers & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK) {
					System.out.println("Left button pressed.");
				}
				if ((modifiers & InputEvent.BUTTON2_MASK) == InputEvent.BUTTON2_MASK) {
					System.out.println("Middle button pressed.");
				}
				if ((modifiers & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) {
					System.out.println("Right button pressed.");
				}
			}

			public void mouseReleased(MouseEvent e) {
				if (e.isPopupTrigger()) {
					myPopupEvent(e);
				}

				if (SwingUtilities.isLeftMouseButton(e)) {
					logger.debug("Left button released.");
					Object obj = getClickedObject(e);
					if (obj instanceof ChildDevice) {
						updateDataPanel((ChildDevice) obj);
					}
				}
				if (SwingUtilities.isMiddleMouseButton(e)) {
					logger.debug("Middle button released.");
				}
				if (SwingUtilities.isRightMouseButton(e)) {
					logger.debug("Right button released.");

					logger.debug("Button : " + e.getButton());
					int x = e.getX();
					int y = e.getY();
					JTree tree = (JTree) e.getSource();
					TreePath path = tree.getPathForLocation(x, y);
					if (path == null) {
						return;
					}

					tree.setSelectionPath(path);
				}
			}
		};

		devices.addMouseListener(ma);
		defaultTreeModel.reload();

	}

	public Object getClickedObject(MouseEvent e) {
		int x = e.getX();
		int y = e.getY();
		JTree tree = (JTree) e.getSource();
		TreePath path = tree.getPathForLocation(x, y);
		if (path == null) {
			return null;
		}

		tree.setSelectionPath(path);

		DefaultMutableTreeNode obj = (DefaultMutableTreeNode) path
				.getLastPathComponent();
		return obj;
	}

	private void reloadUIComponents() {
		defaultTreeModel.reload();
	}

	public static MainJFrame getInstance() {
		return frameInstance;
	}

	public void refreshDeviceList() {
		defaultTreeModel.reload();
	}

	public void addChildToDeviceTree(String ip) {
		ips.add(ip);
		ChildDevice childDevice = new ChildDevice();
		childDevice.setIp(ip);
		root.add(childDevice);
                netMapManager.getChildList().put(childDevice, ip);
		refreshDeviceList();

	}

	public void removeChildFromDeviceTree(String ip) {
		ips.remove(ip);
		refreshDeviceList();

	}

	public void updateDataPanel(final ChildDevice childDevice) {
        Thread thread = new Thread(){
                            public void run()
                            {
		try {

                                    NetMapManager.loadChildDeviceData(childDevice);
                                    ipjLabel.setText(childDevice.getIp());
             
                                    if (childDevice.getCpuInfoList().size() > 0) {
                                            cpuInfoTableModel = new SNMPTableModel(childDevice.getCpuInfoList());
				cpuInfoTable.setModel(cpuInfoTableModel);
				cpuInfoTable.repaint();
			}
                                    if (childDevice.getStorageInfoList().size() > 0) {
                                            diskInfoTableModel = new SNMPTableModel(childDevice.getStorageInfoList());
				storagejTable.setModel(diskInfoTableModel);
				storagejTable.repaint();
			}

                                    if (childDevice.getProgramInfoList().size() > 0) {
                                            processInfoTableModel = new SNMPTableModel(childDevice.getProgramInfoList());
				processesjTable.setModel(processInfoTableModel);
				processesjTable.repaint();
			}
                                    if (childDevice.getNetworkInfoList().size() > 0) {
                                            networkInfoTableModel = new SNMPTableModel(childDevice.getNetworkInfoList());
				networkInfojTable.setModel(networkInfoTableModel);
				networkInfojTable.repaint();
			}

                                    if (childDevice.getDeviceInfoList().size() > 0) {
                                            deviceInfoTableModel = new SNMPTableModel(childDevice.getDeviceInfoList());
				deviceInfoTable.setModel(deviceInfoTableModel);
				deviceInfoTable.repaint();
			}
                        
                                    if(childDevice.getMachineInfo() != null )
                        {
                                        machineInfoTableModel = new MachineInfoTableModel(childDevice.getMachineInfo());
                            machineInfojTable.setModel(machineInfoTableModel);
                            machineInfojTable.repaint();
                        }
                        
                        
                        
		} catch (Exception ex) {
			logger.error(ex);
			JOptionPane.showMessageDialog(null,
					"Unable to update information due to - " + ex.getMessage());
		}

	}
                        };
        thread.start();
        resetDataTabs();
                
		
	}

	private void resetDataTabs() {
                ipjLabel.setText("");
                deviceInfoTable.setModel(new javax.swing.table.DefaultTableModel());
		cpuInfoTable.setModel(new javax.swing.table.DefaultTableModel());
		processesjTable.setModel(new javax.swing.table.DefaultTableModel());
		networkInfojTable.setModel(new javax.swing.table.DefaultTableModel());
		storagejTable.setModel(new javax.swing.table.DefaultTableModel());
                machineInfojTable.setModel(new javax.swing.table.DefaultTableModel());
                deviceInfoTable.repaint();
		cpuInfoTable.repaint();
		processesjTable.repaint();
		networkInfojTable.repaint();
		storagejTable.repaint();
                machineInfojTable.repaint();
                
	}

	public void loadConfiguration() {
		subNetmaskjTextField.setText(NetMapManager.getSubnetMask());
		networkTimeoutjTextField1.setText(String.valueOf(NetMapManager
				.getTimeout()));
		snmpCommunityjTextField1.setText(NetMapManager.getNetworkCommunity());
	}
}
